package com.yayohos.locationmanager.configuration;


import com.yayohos.locationmanager.listener.LocationListener;

import ohos.agp.utils.TextTool;

/**
 * Configurations
 */
public final class Configurations {
    /**
     * Pre-Defined Configurations
     */
    private Configurations() {
        // No instance
    }

    /**
     * Returns a LocationConfiguration that keeps tracking,
     * see also {@linkplain Configurations#silentConfiguration(boolean)}
     *
     * @return LocationConfiguration
     */
    public static LocationConfiguration silentConfiguration() {
        return silentConfiguration(true);
    }

    /**
     * Returns a LocationConfiguration that will never ask user anything and will try to use whatever possible options
     * that application has to obtain location.
     *
     * @param keepTracking Returns a LocationConfiguration that will never ask user anything and will
     *                     try to use whatever possible options
     *                     that application has to obtain location. If there is no sufficient permission,
     *                     provider, etc... then
     *                     LocationManager will call {@linkplain LocationListener#onLocationFailed(int)} silently
     *                     <p>
     *                     # Best use case of this configuration is within Service implementations
     * @return LocationConfiguration
     */
    public static LocationConfiguration silentConfiguration(boolean keepTracking) {
        return new LocationConfiguration.Builder()
                .keepTracking(keepTracking)
                .useDefaultProviders(new DefaultProviderConfiguration.Builder().build())
                .build();
    }

    /**
     * 配置默认的LocationConfiguration
     *
     * @param rationalMessage rationalMessage
     * @param gpsMessage      Returns a LocationConfiguration which tights to default definitions with given messages.
     *                       Since this method is
     *                        basically created in order to be used in Activities, User needs to be asked for
     *                        permission and enabling gps.
     * @return LocationConfiguration
     * @throws IllegalArgumentException rationalMessage cannot be set an null value
     * @throws IllegalArgumentException gpsMessage cannot be set an null value.
     */
    public static LocationConfiguration defaultConfiguration(String rationalMessage, String gpsMessage) {
        if (TextTool.isNullOrEmpty(rationalMessage)) {
            throw new IllegalArgumentException("rationalMessage cannot be set an null value.");
        }
        if (TextTool.isNullOrEmpty(gpsMessage)) {
            throw new IllegalArgumentException("gpsMessage cannot be set an null value.");
        }
        return new LocationConfiguration.Builder()
                .askForPermission(new PermissionConfiguration.Builder().rationaleMessage(rationalMessage).build())
                .useDefaultProviders(new DefaultProviderConfiguration.Builder().gpsMessage(gpsMessage).build())
                .build();
    }
}
